package com.zhangji.practice.config.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @Description： TODO
 * @Date： 2021/8/31 18:59
 * @Author： ZhangJi
 * @Version： 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws Exception {
    Object token = request.getHeader("token");
    if(token==null){
      request.setAttribute("msg","没有权限");
      request.getRequestDispatcher("/index").forward(request,response);
      return false;
    }else{
      return true;
    }
  }

}
